package ynu.edu.ky_elm_springboot3.mapper;

import ynu.edu.ky_elm_springboot3.po.Cart;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface CartMapper {

    @Select("<script>" +
            "select * from cart where userId=#{userId}" +
            "<if test='businessId != null'>" +
            " and businessId=#{businessId}" +
            "</if>" +
            "</script>")
    List<Cart> listCart(@Param("userId") String userId, @Param("businessId") Integer businessId);
    
    @Insert("insert into cart(foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},1)")
    int saveCart(Cart cart);
    
    @Update("update cart set quantity=#{quantity} where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
    int updateCart(Cart cart);
    
    @Delete("<script>" +
            "delete from cart where userId=#{userId} and businessId=#{businessId}" +
            "<if test='foodId != null'>" +
            " and foodId=#{foodId}" +
            "</if>" +
            "</script>")
    int removeCart(@Param("userId") String userId, @Param("businessId") Integer businessId, @Param("foodId") Integer foodId);
} 